﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.BusinessObjects.Transactions;
using Blazing.BusinessObjects.Cms;
using NHibernate.Criterion;

namespace Blazing.BusinessObjects.Queries
{
    public class QrySearchFeedbackItems
    {
        public static IQuery Query(int contentpageId, bool approved)
        {
            string qryStr = @"select f from Contentpage p join p.FeedbackItems f where p.ID = :id and f.IsApproved = :approved order by f.CreatedDate";
            IQuery qry = UnitOfWork.CurrentSession
                .CreateQuery(qryStr);
            qry.SetParameter("id", contentpageId);
            qry.SetParameter("approved", approved);
            qry.SetCacheable(false);

            return qry;    
        }

        public static IQuery QueryFeedbackOnSite(int siteId)
        {
            string qryStr = @"select f from Contentpage p join p.FeedbackItems f where p.Site.ID = :siteId order by f.CreatedDate desc";
            IQuery qry = UnitOfWork.CurrentSession
                .CreateQuery(qryStr);
            qry.SetParameter("siteId", siteId);

            return qry;
        }

        public static IQuery QueryPageWithItem(int feedbackItemId)
        {
            string qryStr = @"select p from Contentpage p join p.FeedbackItems f where f.ID = :feedbackId order by f.CreatedDate";
            IQuery qry = UnitOfWork.CurrentSession
                .CreateQuery(qryStr);
            qry.SetParameter("feedbackId", feedbackItemId);

            return qry;
        }
    }
}
